﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default), this);
    }

    [AjaxPro.AjaxMethod]
    public IList<MySHQ.Model.Entities.TabShop> GetShops(string keyword, int AreaCode)
    {
        //int AreaCode = 440100;
        try
        {
            int lastArea = ((AreaCode + 100) / 100) * 100;
            MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop> bm = new MySHQ.DAL.BaseManager<MySHQ.Model.Entities.TabShop>();
            NHibernate.Criterion.DetachedCriteria dc = NHibernate.Criterion.DetachedCriteria.For<MySHQ.Model.Entities.TabShop>();
            dc.Add(NHibernate.Criterion.Restrictions.And(NHibernate.Criterion.Restrictions.Ge("AreaCode", AreaCode), NHibernate.Criterion.Restrictions.Lt("AreaCode", lastArea)));
            dc.Add(NHibernate.Criterion.Restrictions.Or(NHibernate.Criterion.Restrictions.Like("ShopName", "%" + keyword + "%"), NHibernate.Criterion.Restrictions.Like("Tags", "%" + keyword + "%")));
            NHibernate.Criterion.Order order1 = new NHibernate.Criterion.Order("Sid", false);
            IList<MySHQ.Model.Entities.TabShop> shops = bm.FindAll(dc, 0, 5, order1);
            return shops;
        }
        catch { return null; }
    }
}
